<template>
  <el-dialog :visible.sync="dialogVisible" title="模型保存" @close="closeModal">
    <div style="margin-bottom: 10px;">
      <span>选择模型保存类型：</span>
      <el-radio-group v-model="radio">
        <el-radio :label="1">保存</el-radio>
        <el-radio :label="2">另存为</el-radio>
      </el-radio-group>
    </div>
    <el-form
      v-show="radio == 2"
      :model="modelForm"
      :rules="rule"
      ref="modelRef"
      size="small"
      label-position="right"
      label-width="160px"
    >
      <div class="flex" style="align-items: flex-start;">
        <div class="inputContainer">
          <el-form-item label="模型名称：" prop="mxmc">
            <el-input
              v-model="modelForm.mxmc"
              v-max-length-tip="30"
              v-no-space
              placeholder="请输入模型名称"
            ></el-input>
          </el-form-item>

          <el-form-item label="算法名称：" prop="sfmc">
            <el-input
              v-model="modelForm.sfmc"
              v-max-length-tip="30"
              v-no-space
              placeholder="请输入算法名称"
            ></el-input>
          </el-form-item>

          <el-form-item label="任务完成率：" prop="rwfgl">
            <el-input
              readonly
              v-model="modelForm.rwfgl"
              v-only-number
              maxlength="10"
              placeholder="请输入任务完成率"
            ></el-input>
          </el-form-item>
          <el-form-item label="侧摆角均值" prop="cbjjz">
            <el-input
              readonly
              v-model="modelForm.cbjjz"
              v-only-number
              maxlength="10"
              placeholder="侧摆角均值"
            ></el-input>
          </el-form-item>
        </div>

        <div class="inputContainer">
          <!-- <el-form-item label="基本算法：" prop="jbsf">
            <el-input
              v-model="modelForm.jbsf"
              v-max-length-tip="30"
              v-no-space
              placeholder="请输入基本算法"
            ></el-input>
          </el-form-item> -->
          <!-- <el-form-item label="元任务数量：" prop="yrwsl">
            <el-input
              v-model="modelForm.yrwsl"
              v-only-number
              v-max-length-tip="30"
              v-no-space
              placeholder="请输入元任务数量"
            ></el-input>
          </el-form-item> -->
          <el-form-item label="模型类型：" prop="mxlx">
            <el-input
              v-model="modelForm.mxlx"
              v-max-length-tip="30"
              v-no-space
              placeholder="请输入模型类型"
            ></el-input>
          </el-form-item>
          <el-form-item label="观测时效性均值" prop="gcsxxjz">
            <el-input
              readonly
              v-model="modelForm.gcsxxjz"
              v-only-number
              maxlength="10"
              placeholder="观测时效性均值"
            ></el-input>
          </el-form-item>
          <el-form-item label="太阳高度角均值" prop="tygdjjz">
            <el-input
              readonly
              v-model="modelForm.tygdjjz"
              v-only-number
              maxlength="10"
              placeholder="太阳高度角均值"
            ></el-input>
          </el-form-item>
          <el-form-item label="版本信息：" prop="bbxx">
            <el-input
              v-model="modelForm.bbxx"
              v-max-length-tip="30"
              v-no-space
              placeholder="请输入版本信息"
            ></el-input>
          </el-form-item>
        </div>
      </div>
    </el-form>

    <span slot="footer" class="dialog-footer">
      <el-button type="primary" @click="submitForm('modelRef')">确定</el-button>
      <el-button @click="closeModal">取消</el-button>
    </span>
  </el-dialog>
</template>

<script>
export default {
  props: {
    missionCallback: {
      type: Function,
      default: () => {}
    }
  },
  data() {
    return {
      dialogVisible: false,
      modelForm: {
        mxmc: '',
        sfmc: '',
        rwfgl: '',
        jbsf: '',
        yrwsl: '',
        mxlx: '',
        gcsxxjz: '',
        tygdjjz: '',
        cbjjz: '',
        bbxx: ''
      },
      radio: 1,
      rule: {
        mxmc: [{ required: true, message: '请输入模型名称', trigger: 'blur' }],
        sfmc: [{ required: true, message: '请输入算法名称', trigger: 'blur' }],
        // jbsf: [{ required: true, message: '请输入基本算法', trigger: 'blur' }],
        // yrwsl: [
        //   { required: true, message: '请输入元任务数量', trigger: 'blur' }
        // ],
        mxlx: [{ required: true, message: '请输入模型类型', trigger: 'blur' }]
      },
      kfyyOptions: [
        {
          value: 1,
          label: 'Java'
        },
        {
          value: 2,
          label: 'Python'
        },
        {
          value: 3,
          label: 'C/C++'
        }
      ]
    }
  },
  methods: {
    submitForm(ref) {
      // 是保存，直接提交
      if (this.radio == 1) {
        this.dialogVisible = false
        this.$emit('missionCallback', this.modelForm, this.radio)
        return
      }
      // 是另存为，需要校验
      this.$refs[ref].validate(valid => {
        if (valid) {
          this.dialogVisible = false
          this.$emit('missionCallback', this.modelForm, this.radio)
        } else {
          console.log('error submit!!')
          return false
        }
      })
    },
    openModal(footerData) {
      this.dialogVisible = true
      const rowInfo = JSON.parse(sessionStorage.getItem('missionInfo'))
      this.modelForm = rowInfo
      this.modelForm.rwfgl = footerData.rwwcl
      this.modelForm.gcsxxjz = footerData.gcsxxjz
      this.modelForm.tygdjjz = footerData.tygdjjz
      this.modelForm.cbjjz = footerData.cbjjz
      this.modelForm.id = this.$rou
      this.radio = 1
    },
    closeModal() {
      if (this.$refs.modelRef) {
        this.$refs.modelRef.resetFields()
      }
      this.dialogVisible = false
    }
  }
}
</script>

<style lang="scss" scoped>
::v-deep .el-table__expanded-cell {
  padding: 0 55px;
}

::v-deep .el-table__body tr:hover > td {
  background-color: transparent !important;
}

::v-deep .el-table .el-table__header-wrapper thead tr th {
  background-color: transparent;
}

::v-deep .el-input--small .el-input__inner {
  border-color: #2d65ad !important;
}

::v-deep .el-select {
  width: 100%;
}
.inputContainer {
  width: 50%;
}
</style>
